from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api import stock, backtest, forecast

app = FastAPI()

# 设置CORS中间件，允许所有来源的请求，这在开发阶段很方便
# 在生产环境中，应该限制为前端应用的实际域名
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(stock.router, prefix="/api/stock", tags=["stock"])
app.include_router(backtest.router, prefix="/api/backtest", tags=["backtest"])
app.include_router(forecast.router, prefix="/api/forecast", tags=["forecast"])

@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/api/test")
def test_endpoint():
    return {"message": "Backend is working!"} 